<?php
/***********************************************************
    [EasyTalk] (C)2009 - 2011 nextsns.com
    This is NOT a freeware, use is subject to license terms

    @Filename SettingAction.class.php $

    @Author hjoeson $

    @Date 2011-01-09 08:45:20 $
*************************************************************/

class SettingAction extends Action {

    public function _initialize() {
        A('Api')->tologin();
        parent::init();
        $this->assign('usertemp',usertemp($this->my));
        $this->assign('menu','setting');
        $this->assign('subname',L('setcenter'));
    }

    public function index() {
//        $province=D('District')->where('level=1')->select();
//        $this->assign('province',$province);
		$fuwufenlei=M('skill');
		$map['parent_id']=1;
		$result_fuwufenglei=$fuwufenlei->where($map)->findAll();
		$this->assign('vol_fuwu',$result_fuwufenglei);

		$Province=M('region');
		$map['parent_id']=1;
		$result_qinyous=$Province->where($map)->findAll();
		//echo json_encode($result);
		$this->assign('vol',$result_qinyous);


		//把服务信息发送到index.htm文件，显示此用户自己提供的服务信息汇总。
		$fuwu=M('fuwu');
		$result_fuwu=$fuwu->where("user_id='".$this->my['user_id']."'")->findall();
		$this->assign('volfuwulist',$result_fuwu);
//		$result_fuwuid=$fuwu->where("user_id='".$this->my['user_id']."'")->getField('fuwuid');
//		$this->assign('volfuwuid',$result_fuwuid);
        $this->display();
    }

	 public function baseinfo(){
	
	    //header("Content-Type:text/html; charset=utf-8");
		$Province=M('region');
		$map['parent_id']=1;
		$result=$Province->where($map)->findAll();
		//echo json_encode($result);
		$this->assign('vol',$result);
		$this->assign('hvol',$result);
		//dump($result);
		$this->display();
	}

	public function ajaxData(){
		$map['parent_id']=$_POST['pid'];//获取post传递的pid参数
		$Province=M('region');//实例化
		$result=$Province->where($map)->findAll();//带入参数查询
		if(!empty($result)){//判断是否有结果
			$this->ajaxReturn($result,'ok',1);//如果有结果 返回一个json格式的数据
		}else{
			$this->ajaxReturn(0,'error',0);//如果没有返回空
		}
	}
	public function ajaxData_fuwu(){
		$map['parent_id']=$_POST['pid'];//获取post传递的pid参数
		$fuwufenlei=M('skill');//实例化
		$result=$fuwufenlei->where($map)->findAll();//带入参数查询
		if(!empty($result)){//判断是否有结果
			$this->ajaxReturn($result,'ok',1);//如果有结果 返回一个json格式的数据
		}else{
			$this->ajaxReturn(0,'error',0);//如果没有返回空
		}
	}

    public function jia_fuwu(){
		$fuwuu=M('fuwu');
		$fuwufenlei=M('skill');
		$Province=M('region');
		$ctent=D('Content'); //这个地方我担心是否会有性能问题？是否没有必要实例化一个Content？ 5/24/2011 luozhengfeng -->6/27/2011 有必要
		$data=array();
		 $mapfuwulastid['user_id']=$this->my['user_id'];
		 $data['user_id']= $this->my['user_id'];
		 $data['user_name']= $this->my['user_name'];
		 $data['fuleibie']=trim($_POST['fufenlei']);		 
		 $data['zileibie']=trim($_POST['zifenlei']);
		  if($_POST['zifenlei']==-1){
					Cookie::set('setok','fuwu_leibieming_need');
					header('location:'.SITE_URL.'/Setting');
					exit;
				}

		 $mapfufenlei['skill_id']=$_POST['fufenlei'];
		 $mapzifenlei['skill_id']=$_POST['zifenlei'];

		$fleibieming=$fuwufenlei->where($mapfufenlei)->getField('skill_name');
		$zleibieming=$fuwufenlei->where($mapzifenlei)->getField('skill_name');
		$fuwuleibieming=$fleibieming.'-'.$zleibieming;

	     $data['fuwuleibieming']=$fuwuleibieming;

		 $fuwubiaoti= daddslashes(clean_html(trim($_POST["fuwubiaoti"])));
		 if(!$fuwubiaoti){
					Cookie::set('setok','setting5');
					header('location:'.SITE_URL.'/Setting');
					exit;
				}
		 $data['fuwubiaoti']=$fuwubiaoti;
		 $data['fuwujiage']=trim($_POST['fuwujiage']);
		 $data['yuerdanbao']=trim($_POST['yuerdanbao']);
		 $fuwuxiangqing= daddslashes($ctent->replace(trim($_POST["fuwuxiangqing"])));
		 if(!$fuwuxiangqing){
					Cookie::set('setok','fuwu_info_input');
					header('location:'.SITE_URL.'/Setting');
					exit;
				}
		 $data['fuwuxiangqing']=$fuwuxiangqing;
		 $zidingyiwenti= daddslashes(clean_html(trim($_POST["zidingyiwenti"])));
		 $data['zidingyiwenti']=$zidingyiwenti;
		 if($_POST['qinyou']){ 
				 //where("id='$val[topic_id]'")
		 		 $data['shifouweiqinyou']=$_POST['qinyou'];		
				 $data['hewodeganxi']=trim($_POST['hewodeganxi']);		
				 $data['suozaidizhi']=$_POST['lone'].' '.$_POST['ltwo'].' '.$_POST['lthree'];	
				 $data['suozaidizhi_ming']=$Province->where("region_id='$_POST[lone]'")->getField('region_name').' '.$Province->where("region_id='$_POST[ltwo]'")->getField('region_name').' '.$Province->where("region_id='$_POST[lthree]'")->getField('region_name');
		 }
		 $data['fuwuzhuangtai']=TRUE;
		 $data['fuwujianlishijian']=time();
		 $data['fuwuxiugaishijian']=time();
         $list=$fuwuu->data($data)->add();
		 if($list!==false){
			  //把发布的服务存放一份到content表中.6/21/2011 Luozhengfeng
			  unset($data);
			  M('Users')->setInc('fuwuzongshu','user_id='.$this->my['user_id'],1); 
			  $list_s=$fuwuu->where("user_id='".$this->my['user_id']."'")->order('fuwujianlishijian desc')->find(); 
			  $this->assign('list_s',$list_s);
			  if($list_s['shifouweiqinyou']){
				$content_body.="的".$list_s['hewodeganxi'];
			  }else{
					$content_body="";
				}
			  $content_body.=" #发布了服务#: ".$list_s['fuwubiaoti']." 单价: ".$list_s['fuwujiage']." 详情: ";
			  $content_body.=$list_s['fuwuxiangqing'];
			  $data['content_body']=$content_body;
			  $data['fuwuid']=$list_s['fuwuid'];
			  $data['user_id']=$list_s['user_id'];
			  $data['posttime']=time();
			  $data['filetype']="fuwu";
			  //echo $list_s['fuwuid']." time: ".time();
			  $list_ctent=$ctent->data($data)->add();
			  M('Users')->setInc('msg_num','user_id='.$this->my['user_id'],1); 
			  Cookie::set('setok','setting_fuwuok');
			  //$this->success('数据保存成功！');
			}else{
			  Cookie::set('setok','setting_fuwuno');
			  //$this->error('数据保存失败！');
			}
         header('location:'.SITE_URL.'/Setting');
	}

	public function offline_fuwu(){
		$fuwuid=$_GET['id'];
	  if(!empty($fuwuid)) {
			$fuwuu=M('fuwu');
			$userid=$fuwuu->where("fuwuid='$fuwuid'")->getField('user_id');
			if($this->my['isadmin']>0 || $userid==$this->my['user_id']){
				$result	= $fuwuu->delete($fuwuid);
				if(false !== $result) {
				//$this->assign("jumpUrl","../.."); 
				//$this->success('服务下线成功！');	
				M('users')->setDec('fuwuzongshu','user_id='.$this->my['user_id'],1); 
				header('location:'.SITE_URL.'/Setting');			
			
				//同时在Content表中删除对应的记录 6/23/2011
				$delcontent=D('Content');
				$cid=$delcontent->where("fuwuid='$fuwuid'")->getField('content_id');
					if ($cid) {			
						$data = $delcontent->where("content_id='$cid'")->find(); 
						if ($this->my['isadmin']>0 || $data['user_id']==$this->my['user_id']) {
							if ($data) {
								$delcontent->where("content_id='$cid'")->delete();
								//删除话题
								$ctp=D('Content_topic');
								$cdata=$ctp->where("content_id='$cid'")->select();
								if (is_array($cdata)) {
									foreach ($cdata as $val) {
										D('Topic')->where("id='$val[topic_id]'")->setDec('topictimes');
									}
								}
								$ctp->where("content_id='$cid'")->delete();
								//消息数更新
								if ($data['replyid']) {
									$delcontent->setDec('replytimes',"content_id='$data[replyid]'");
								} else {
									if ($data['retid']) {
										$delcontent->setDec('zftimes',"content_id='$data[retid]'");
									}
									D('Users')->updatemsgnum($data['user_id'],'--');
								}
							}
							//删除mention
							D('Content_mention')->where("cid='$cid'")->delete();
						}
						return 'success';
					} else {
						return '删除失败，可能您没有权限！';
					}
				} else {
					return '删除此id失败，可能此广播无法找到对应的id！';
				}




			}else{
				Cookie::set('setok','setting_no');
				exit;
				//$this->error('服务下线出错！');
			}
		}else{
			Cookie::set('setok','setting_no');
			exit;
			//$this->error('服务不存在！');
		}
	
	}
	public function gai_fuwu(){
		    $fuwufenlei=M('skill');
			$fuwuu=M('fuwu');
			$fuwuid=$_POST['fuwuid'];;
			$mapfuwuid['fuwuid']=$fuwuid;
			$userid=$fuwuu->where("fuwuid='$fuwuid'")->getField('user_id');
			//if($this->my['isadmin']>0 || $userid==$this->my['user_id']){
			$vo=$fuwuu->where($mapfuwuid)->find();			
			if($vo&&($userid==$this->my['user_id']||$this->my['isadmin']>0)) {
				$this->assign('vo',$vo);
				//dump($vo);
				//echo $vo['fuwujiage'];
				//echo vo.fuwujiage;
				$map['parent_id']=1;
				$result_fuwufenglei=$fuwufenlei->where($map)->findAll();
				$this->assign('vol_fuwu',$result_fuwufenglei);

				$Province=M('region');
				$map['parent_id']=1;
				$result_qinyous=$Province->where($map)->findAll();
				//echo json_encode($result);
				$this->assign('vol',$result_qinyous);

				//$this->display();

				$fuwufenlei=M('skill');
				$ctent=D('Content');
				$data=array();
				// $data['user_id']= $this->my['user_id'];
				if($_POST['fufenlei']!=$vo['fuleibie']){
					$data['fuleibie']=trim($_POST['fufenlei']);					
				}
				
				if($_POST['zileibie']!=$vo['zileibie']){
					$data['zileibie']=trim($_POST['zifenlei']);					
				}
					$mapfufenlei['skill_id']=$_POST['fufenlei'];
					$fleibieming=$fuwufenlei->where($mapfufenlei)->getField('skill_name');
					$mapzifenlei['skill_id']=$_POST['zifenlei'];				
					$zleibieming=$fuwufenlei->where($mapzifenlei)->getField('skill_name');
					$fuwuleibieming=$fleibieming.'-'.$zleibieming;
					$data['fuwuleibieming']=$fuwuleibieming;
				 
				 $fuwubiaoti= daddslashes(clean_html(trim($_POST["fuwubiaoti"])));
				 if(!$fuwubiaoti){
					Cookie::set('setok','setting5');
					header('location:'.SITE_URL.'/Setting');
					exit;
				}
				if($fuwubiaoti!=$vo['fuwubiaoti']){
					$data['fuwubiaoti']=$fuwubiaoti;
				 }
				if(trim($_POST['fuwujiage'])!=$vo['fuwujiage']){
					$data['fuwujiage']=trim($_POST['fuwujiage']);
				 }
				if(trim($_POST['yuerdanbao'])!=$vo['yuerdanbao']){
					$data['yuerdanbao']=trim($_POST['yuerdanbao']);
				 }
				 $fuwuxiangqing= daddslashes($ctent->replace(trim($_POST["fuwuxiangqing"])));
				if($fuwuxiangqing!=$vo['fuwuxiangqing']){
					$data['fuwuxiangqing']=$fuwuxiangqing;
				 }				
				 $zidingyiwenti= daddslashes(clean_html(trim($_POST["zidingyiwenti"])));
				if($zidingyiwenti!=$vo['zidingyiwenti']){
					$data['zidingyiwenti']=$zidingyiwenti;
				 }	
				if($_POST['qinyou']){
						if($_POST['qinyou']!=$vo['shifouweiqinyou']){
							$data['shifouweiqinyou']=$_POST['qinyou'];	
						}
						if(trim($_POST['hewodeganxi'])!=$vo['hewodeganxi']){
							$data['hewodeganxi']=trim($_POST['hewodeganxi']);
						}
						$suozaidizhi=$_POST['lone'].' '.$_POST['ltwo'].' '.$_POST['lthree'];
						if($suozaidizhi!=$vo['suozaidizhi']){
							$data['suozaidizhi']=$suozaidizhi;
						}							 
				 }
				 $data['fuwuzhuangtai']=TRUE;
				 $data['fuwuxiugaishijian']=time();
				 $list=$fuwuu->where($mapfuwuid)->data($data)->save();
				 if($list!==false){
					  //在修改用户服务的同时也 更新服务项 6/21/2011
					  unset($data);
					  $list_s=$fuwuu->where("user_id='".$this->my['user_id']."'")->order('fuwuxiugaishijian desc')->find(); 
					  $this->assign('list_s',$list_s);	
					  $content_body.=" #发布了服务#: ".$list_s['fuwubiaoti']." 单价: ".$list_s['fuwujiage']." 详情: ";
					  //$content_body.=$list_s['user_name']." 发布了服务: ".$list_s['fuwubiaoti']." 价格: ".$list_s['fuwujiage']."元/次或/小时  详情: ";
					  $content_body.=$list_s['fuwuxiangqing'];
					  $data['content_body']=$content_body;
					  //$data['fuwuid']=$list_s['fuwuid'];
					 // $data['user_id']=$list_s['user_id'];
					  //$data['posttime']=time();
					  //$data['filetype']="service";
					  //echo $list_s['fuwuid']." time: ".time();
					  $list_ctent=$ctent->where("fuwuid='".$list_s['fuwuid']."'")->data($data)->save();

					  header('location:'.SITE_URL.'/Setting');
//					  $this->success('数据保存成功！');
//					  $this->assign("jumpUrl","../..");
					}else{
					  Cookie::set('setok','setting_no');
					  //$this->error('数据保存失败！');
					}
				 header('location:'.SITE_URL.'/Setting');

			}else{				
				//exit('编辑项不存在！');
				Cookie::set('setok','setting_no');
				exit;
				header('location:'.SITE_URL.'/Setting');
			}
	}


	public function editfuwu(){
		if(!empty($_GET['id'])) {
		    $fuwufenlei=M('skill');
			$fuwuu=M('fuwu');
			$mapfuwuid['fuwuid']=$_GET['id'];
			$vo=$fuwuu->where($mapfuwuid)->find();
			//$vo=$fuwuu->getById($_GET['id']);
			if($vo) {
				//print_r($vo);
				$this->assign('vo',$vo);
				//dump($vo);
				//echo $vo['fuwujiage']; output 11
				//echo $vo.fuwujiage; output Arrayfuwujiage
				$map['parent_id']=1;
				$result_fuwufenglei=$fuwufenlei->where($map)->findAll();
				$this->assign('vol_fuwu',$result_fuwufenglei);

				$Province=M('region');
				$map['parent_id']=1;
				$result_qinyous=$Province->where($map)->findAll();
				//echo json_encode($result);
				$this->assign('vol',$result_qinyous);

				$this->display();

				
			}else{
				exit('编辑项不存在！');
			}
		}else{
			exit('编辑项不存在！');
		}
	}
	
	


    public function doset() {
        $user=M('Users');
        $ctent=D('Content');
        $data=array();

		$city_code=$_POST['lone'].' '.$_POST['ltwo'].' '.$_POST['lthree'].' '.$_POST['hone'].' '.$_POST['htwo'].' '.$_POST['hthree'];

		// get the live and home's sheng/city/xian 's address
		$mapls['region_id']=$_POST["lone"];
		$maplc['region_id']=$_POST["ltwo"];
		$maplx['region_id']=$_POST["lthree"];

		$maphs['region_id']=$_POST["hone"];
		$maphc['region_id']=$_POST["htwo"];
		$maphx['region_id']=$_POST["hthree"];

		$Province=M('region');
		$lshenfeng=trim($Province->where($mapls)->getField('region_name'));
		$lcity=trim($Province->where($maplc)->getField('region_name'));
		$lxian=trim($Province->where($maplx)->getField('region_name'));

		$hshenfeng=trim($Province->where($maphs)->getField('region_name'));
		$hcity=trim($Province->where($maphc)->getField('region_name'));
		$hxian=trim($Province->where($maphx)->getField('region_name'));
	

        //$city=trim($_POST["livesf"].' '.$_POST["livecity"]);
		$live_city=trim($lshenfeng.' '.$lcity.' '.$lxian);
		$home_city=trim($hshenfeng.' '.$hcity.' '.$hxian);
		
		$userqq=$_POST['userqq'];
		$userweibo=$_POST['userweibo'];

        $nickname= daddslashes(clean_html(trim($_POST["nickname"])));
        $gender= $_POST["gender"];
        //$city=trim($_POST["livesf"].' '.$_POST["livecity"]);
        $info= daddslashes($ctent->replace(trim($_POST["info"])));

        if(!preg_match('/^[0-9a-zA-Z\xe0-\xef\x80-\xbf._-]+$/i',$nickname)) {
            Cookie::set('setok','setting2');
            header('location:'.SITE_URL.'/Setting/baseinfo');
            exit;
        }
        if (!$nickname || !$gender || !$live_city) {
            Cookie::set('setok','setting1');
            header('location:'.SITE_URL.'/Setting/baseinfo');
            exit;
        }
		if($live_city && $live_city!=$this->my['live_city']){
		    $data['live_city']=$live_city;
		}
		if($home_city && $home_city!=$this->my['home_city']){
		    $data['home_city']=$home_city;
		}
		if($city_code && $city_code!=$this->my['city_code']){
			$data['city_code']=$city_code;
		}
        if ($live_city && $live_city!=$this->my['live_city'] && $live_city!="选择省份"){
            $data['live_city']=$live_city;
        }
		if ($home_city && $home_city!=$this->my['home_city'] && $home_city!="选择省份"){
            $data['home_city']=$home_city;
        }
//        if ($city && $city!=$this->my['live_city'] && $city!="选择省份 选择城市"){
//            $data['live_city']=$city;
//        }

        if ($gender!=$this->my['user_gender']){
            $data['user_gender']=$gender;
        }
		if ($userqq!=$this->my['userqq']){
            $data['userqq']=$userqq;
        }
		if ($userweibo!=$this->my['userweibo']){
            $data['userweibo']=$userweibo;
        }
        if ($info!=$this->my['user_info']){
            $data['user_info']=$info;
        }
        if ($nickname && $nickname!=$this->my['nickname'] && $this->my['user_auth']==0) {
            if (StrLenW($nickname)<=12 && StrLenW($nickname)>=1) {
                $newnickname=$user->where("user_name='$nickname' OR nickname='$nickname'")->find();
                if ($newnickname) {
                    Cookie::set('setok','setting4');
                    header('location:'.SITE_URL.'/Setting/baseinfo');
                    exit;
                } else {
                    $data['nickname']=$nickname;
                    //atuserlist
                    D('Atusers')->where("atuname='".$this->my['user_name']."'")->setField('atnickname',$nickname);
                }
            } else {
                Cookie::set('setok','setting2');
                header('location:'.SITE_URL.'/Setting/baseinfo');
                exit;
            }
        }
        $user->where("user_id='".$this->my['user_id']."'")->data($data)->save();
        Cookie::set('setok','setting3');
        header('location:'.SITE_URL.'/Setting/baseinfo');
    }

    public function doface() {
        import("@.ORG.UploadFile");
        $uploadurl='/Public/attachments/head/temp/';
        $uploadurl2=__PUBLIC__.'/attachments/head/temp/';
        $upload = new UploadFile();
        $upload->maxSize  = 2097152 ;
        $upload->allowExts  = explode(',','jpg,gif,png,jpeg');
        $upload->savePath =  ET_ROOT.$uploadurl;
        $upload->thumb =  false;
        $upload->autoSub = false;
        $upload->saveRule = time;
        $upload->thumbRemoveOrigin = true;
        if($upload->upload()) {
            $uploadList = $upload->getUploadFileInfo();
            $picinfo=getimagesize(ET_ROOT.$uploadurl.$uploadList[0]['savename']);
            echo '<script language="Javascript">parent.document.getElementById("cropbox").src="'.$uploadurl2.$uploadList[0]['savename'].'";parent.document.getElementById("imgpath").value="'.$uploadurl.$uploadList[0]['savename'].'";parent.document.getElementById("cropboxdiv").style.display="block";parent.document.getElementById("loadpic").style.display="none";parent.frames.faceinit("'.$picinfo[0].'");parent.document.getElementById("picpath").innerHTML="'.L('head_filename').$uploadList[0]['savename'].'";</script>';
        } else {
            echo '<script language="Javascript">parent.document.getElementById("loadpic").style.display="none";alert("'.L('head_upload_error').'");</script>';
        }
    }

    public function doface2() {
        $ysw=$_POST['ysw'];
        if ($ysw>460) {
            $zoom=intval($ysw)/460;
        } else {
            $zoom=1;
        }
        $x=$_POST['x']*$zoom;
        $y=$_POST['y']*$zoom;
        $w=$_POST['w']*$zoom;
        $h=$_POST['h']*$zoom;
        $imgpath=ET_ROOT.$_POST['imgpath'];
        $ext=strtolower(getExtensionName($imgpath));

        import("@.ORG.IoHandler");
        $IoHandler = new IoHandler();
        if($ext!='jpg' && $ext!='jpeg' && $ext!='gif' && $ext!='png') {
            $IoHandler->DeleteFile($imgpath);
            Cookie::set('setok','face2');
            header('location:'.SITE_URL.'/Setting/face');
            exit;
        }
        $image_path = ET_ROOT.'/Public/attachments/head/'.date('Ymd').'/';
        if(!is_dir($image_path)) {
            mkdir($image_path);
        }
        $f=date('His');
        //大图片
        $filename=$f.'_big.'.$ext;
        $dst_file = $image_path.$filename;
        $make_result = makethumb($imgpath,$dst_file,max(10,min(120,$w)),max(10,min(120,$h)),0,0,$x,$y,$w,$h);
        //小图片
        $filename=$f.'_small.'.$ext;
        $dst_file = $image_path.$filename;
        $make_result = makethumb($imgpath,$dst_file,max(10,min(50,$w)),max(10,min(50,$h)),0,0,$x,$y,$w,$h);
        $IoHandler->DeleteFile($imgpath);

        $user=M('Users');
        $data['user_head']=date('Ymd').'/'.$filename;
        $user->where("user_id='".$this->my['user_id']."'")->data($data)->save();
        Cookie::set('setok','face1');
        header('location:'.SITE_URL.'/Setting/face');
    }

    public function doaccount() {
        $pass=md5(md5($_POST["pass"]));
        $newpass1= md5(md5($_POST["newpass1"]));
        $newpass2= md5(md5($_POST["newpass2"]));
        if ($pass==$this->my['password']) {
            if ($newpass1!=$newpass2 || !trim($_POST["newpass1"])) {
                Cookie::set('setok','account1');
            } else {
                //ucenter 修改密码
                if (ET_UC==TRUE) {
                    $ucresult = uc_user_edit($this->my['user_name'],$_POST["pass"],$_POST["newpass2"]);
                    if($ucresult!=1) {
                        Cookie::set('setok','account3');
                        header('location:'.SITE_URL.'/Setting/account');
                        exit;
                    }
                }
                //end
                D('Users')->where("user_id='".$this->my['user_id']."'")->setField('password',$newpass1);
                Cookie::set('setok','account2');
            }
        } else {
            Cookie::set('setok','account3');
        }
        header('location:'.SITE_URL.'/Setting/account');
    }

    public function domailauth() {
        if ($this->my['auth_email']==0) {
            $sendurl=randStr(20);
            $sendurl=base64_encode($this->my['user_id'].":".$sendurl);
            $url=SITE_URL."/Setting/doauth/auth/{$sendurl}";
            $send="<meta http-equiv='Content-Type' content='text/html; charset=UTF-8' />
            <p>".L('mailauth_title').$this->my['nickname']."(<small>@".$this->my['user_name']."</small>)：</p>
            <p style='text-indent:2em'>".L('mailauth_this').$this->site['sitename'].L('mailauth_tip1')."<a href='$url' target='_blank'>".L('mailauth_click')."</a>".L('mailauth_copyurl')."</p>
            <p>".L('authurl').":<a href='$url' target='_blank'>$url</a></p>
            <p style='text-align:right'>".$this->site['sitename']." ".date('Y-m-d H:i')."</p>";
            $title=$this->site['sitename'].L('mailauth');

            A('Api')->sendMail($title,$send,$this->my['mailadres']);

            $user=M('Users');
            $data['auth_email']=$sendurl;
            $user->where("user_id='".$this->my['user_id']."'")->data($data)->save();

            Cookie::set('setok','mail1');
        }
        header('location:'.SITE_URL.'/Setting/mailauth');
    }

    public function changemail() {
        $user=D('Users');
        $new_email= daddslashes(trim($_POST["email"]));
        if(!strpos($new_email,"@")) {
            Cookie::set('setok','mail2');
        } else {
            if ($new_email && $new_email!=$this->my['mailadres']) {
                $row = $user->field('mailadres')->where("mailadres='$new_email'")->find();
                if ($row) {
                    Cookie::set('setok','mail3');
                } else {
                    $data['mailadres']=$new_email;
                    $data['auth_email']=0;
                    $user->where("user_id='".$this->my['user_id']."'")->data($data)->save();
                    Cookie::set('setok','mail8');
                }
            } elseif ($new_email==$this->my[mailadres]){
                Cookie::set('setok','mail4');
            } else {
                Cookie::set('setok','mail5');
            }
        }
        header('location:'.SITE_URL.'/Setting/mailauth');
    }

    public function doauth() {
        $_authmsg=daddslashes($_GET['auth']);
        $authmsg=base64_decode($_authmsg);
        $tem=explode(":",$authmsg);
        $send_id=$tem[0];
        $user=D('Users');

        $row = $user->field('auth_email')->where("user_id='$send_id'")->find();
        $auth_email=$row['auth_email'];
        if ($_authmsg==$auth_email) {
            $data['auth_email']=1;
            $user->where("user_id='$send_id'")->data($data)->save();
            Cookie::set('setok','mail6');
        } else {
            Cookie::set('setok','mail7');
        }
        header('location:'.SITE_URL.'/Setting/mailauth');
    }

		public function changedianhua() {
        $user=D('Users');
        $shoujihaoma= daddslashes(trim($_POST["shoujihaoma"]));
		$gudingdianhua= daddslashes(trim($_POST["gudingdianhua"]));	
        
            if ($shoujihaoma && $shoujihaoma!=$this->my['shoujihaoma']) {
                $data['shoujihaoma']=$shoujihaoma;
				$i=$i+1;                
             }
			if ($gudingdianhua && $gudingdianhua!=$this->my['gudingdianhua']) {
                $data['gudingdianhua']=$gudingdianhua;
				$i=$i+2;                
             }
			if ($i>2){
				$data['auth_dianhua']=2;
				$user->where("user_id='".$this->my['user_id']."'")->data($data)->save();
				//Cookie::set('setok','mail8');			
			}           
           
        header('location:'.SITE_URL.'/Setting/mailauth');
    }

	public function dotruename() {
        import("@.ORG.UploadFile");
        $upload = new UploadFile();
        $upload->maxSize  = 2097152 ;
        $upload->allowExts  = array('jpg','gif','png','jpeg');
        $upload->savePath =  './Public/attachments/truename/';
        $upload->thumb =  true;
        $upload->suofang = 1;
        $upload->thumbPrefix   =  '';
        $upload->thumbMaxWidth =  '120';
        $upload->thumbMaxHeight = '120';
        $upload->subType = 'date';
        $upload->autoSub = true;
        $upload->saveRule = time;
        $upload->thumbRemoveOrigin = true;
		$user=M('Users');

        if($upload->upload()) {
            $uploadList = $upload->getUploadFileInfo();
            
            $data['truename_head']=date('Ymd').'/'.$uploadList[0]['savename'];			
        }
			if ($_POST["truename"] && $_POST["truename"]!=$this->my['truename']) {
				$data['truename'] = $_POST["truename"];
			}
			if ($_POST["shenfenzheng"] && $_POST["shenfenzheng"]!=$this->my['shenfenzheng']) {
				$data['shenfenzheng'] = $_POST["shenfenzheng"];
			}
			if ($_POST["zhifubao"] && $_POST["zhifubao"]!=$this->my['zhifubao']) {
				$data['zhifubao'] = $_POST["zhifubao"];
			}
			
			$data['auth_truename'] = 2;
            $user->where("user_id='".$this->my['user_id']."'")->data($data)->save();
        header('location:'.SITE_URL.'/Setting/mailauth');
    }



    public function tixian(){	
		$users=M('tixian');
		$result=$users->where("user_id='".$this->my['user_id']."'")->findall();
		//echo json_encode($result);
		$this->assign('vol',$result);
		//dump($result);
//		Load('extend'); 
//		echo get_client_ip();
		$this->display();
		header('location:'.SITE_URL.'/Setting/tixian');
	}
	public function tixianjilv(){
		$tixianjilu = M('tixian');
		$data=array();
		$data['user_id']=$this->my['user_id'];
		$data['user_name']=$this->my['user_name'];
		$data['truename']=$this->my['truename'];
		$data['shenfenzheng']=$this->my['shenfenzheng'];
		$data['userqq']=$_POST["userqq"];
		$data['shoujihaoma']=$this->my['shoujihaoma'];
		$data['zhifubao']=$_POST["zhifubao"];
		$data['tixianjinger']=$_POST["tixianjinger"];
		$data['tianxianshijian']=time();
		if($this->my['yongfuyuer']<30){
			 exit('只有当用户余额大于或等于30元时才建议提议.');
		}
		if($this->my['yongfuyuer']<$_POST["tixianjinger"]){
			 exit('申请提现额度不能超过您的全部余额!');
		}
		if($_POST["tixianjinger"]<10){
			 exit('申请提现额度需大于10元!');
		}
		$user = M('Users');
		$data['yongfuyuer']=$this->my['yongfuyuer']-$_POST["tixianjinger"];
		$user->where("user_id='".$this->my['user_id']."'")->data($data)->save();
		$data['yongfuyuer']=$this->my['yongfuyuer']-$_POST["tixianjinger"];
		$data['shenhezhangtai']=2;
		$list=$tixianjilu->data($data)->add();
		 if($list!==false){ 
			 //Cookie::set('setok','setting_ok');
			 $this->success('数据保存成功！');			  
			}else{
			  //print_r($data);
			  //$this->display();
			  //Cookie::set('setok','setting_no');
			  $this->error('数据保存失败！');
			}		
	}


	public function chongzhi(){	
		$chongzhi = M('chongzhi');
		$result=$chongzhi->where("user_id='".$this->my['user_id']."'")->findall();
		//echo json_encode($result);
		$this->assign('vol',$result);
		//dump($result);
//		Load('extend'); 
//		echo get_client_ip();
		$this->display();
		//header('location:'.SITE_URL.'/Setting/tixian');
	}

	public function chongzhi_return(){	
		require_once("./pay/Alipay/class/alipay_notify.php");
		require_once("./pay/Alipay/alipay_config.php");
		//echo $return_url;
		//echo "test";

		//构造通知函数信息
		$alipay = new alipay_notify($partner,$key,$sign_type,$_input_charset,$transport);
		//计算得出通知验证结果
		$verify_result = $alipay->return_verify();

		if($verify_result) {//验证成功
			/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
			//请在这里加上商户的业务逻辑程序代码
			
			//——请根据您的业务逻辑来编写程序（以下代码仅作参考）——
			//获取支付宝的通知返回参数，可参考技术文档中页面跳转同步通知参数列表
			$trade_no		   = $_GET['trade_no'];			//支付宝交易号
			$dingdan           = $_GET['out_trade_no'];     //获取订单号
			$total_fee         = $_GET['total_fee'];	    //获取总价格
			$subject		   = $_GET['subject'];			//获取标题
			$body			   = $_GET['body'];				//服务描述
			$buyer_email	   = $_GET['buyer_email'];		//买家账号
			$trade_status	   = $_GET['trade_status'];		//交易状态
			$notify_time	   = $_GET['notify_time'];		//支付宝通知时间

			
			$dingdan_ids = explode("__", $dingdan);
			$subject_names = explode("__", $subject);
			//用户id和用户名不符合
			if($dingdan_ids[0]!==$this->my['user_id'] || $subject_names[0]!==$this->my['user_name']){
				exit('您的标识错误');
			}

			//防乱发GET
			if(!$_GET['sign'] && !$_GET['seller_id']){
				exit('You are bad!!');
			}
			
			if($_GET['trade_status'] == 'TRADE_FINISHED' || $_GET['trade_status'] == 'TRADE_SUCCESS') {
				//判断该笔订单是否在商户网站中已经做过处理（可参考“集成教程”中“3.4返回数据处理”）
					//如果没有做过处理，根据订单号（out_trade_no）在商户网站的订单系统中查到该笔订单的详细，并执行商户的业务程序
					//如果有做过处理，不执行商户的业务程序
					$chongzhi = M('chongzhi');
					$data=array();
					$data['user_id']=$this->my['user_id'];
					$data['user_name']=$this->my['user_name'];
					$data['truename']=$this->my['truename'];
					$data['shenfenzheng']=$this->my['shenfenzheng'];
					$data['userqq']=$this->my['userqq'];
					$data['shoujihaoma']=$this->my['shoujihaoma'];
					$data['zhifubao']=$buyer_email;
					if($this->my['zhifubao']!==$buyer_email){
						$buyer_email_users=$buyer_email.$this->my['zhifubao'];
						M('Users')-> where("user_id='".$this->my['user_id']."'")-> setField( 'zhifubao',$buyer_email_users ); 
					}
					$data['total_fee']=$total_fee;
					$data['yongfuyuer']=$total_fee+$this->my['yongfuyuer'];
					M('Users')-> where("user_id='".$this->my['user_id']."'")-> setField( 'yongfuyuer',$data['yongfuyuer'] ); 
					$data['trade_no']=$trade_no;
					$data['dingdan']=$dingdan;
					$data['subject']=$subject;
					$data['body']=$body;
					$data['trade_status']=$trade_status;
					$data['notify_time']=$notify_time;
					$data['xianrushijian']=time();					
					//print_r($data);	
					$list=$chongzhi->data($data)->add();
					 if($list!==false){ 
						 //Cookie::set('setok','setting_ok');
						// $this->success('数据保存成功！');
							  
						}else{
						  //print_r($data);
						  //$this->display();
						  //Cookie::set('setok','setting_no');
						  $this->error('数据保存失败！');
						}		
			}
			else {
			  echo "trade_status=".$_GET['trade_status'];
			}
			//——请根据您的业务逻辑来编写程序（以上代码仅作参考）——
			
			/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
		}
		else {
			//验证失败
			//如要调试，请看alipay_notify.php页面的return_verify函数，比对sign和mysign的值是否相等，或者检查$veryfy_result有没有返回true
			echo "网站验证故障!";
		}
		$this->assign('trade_no',$trade_no);
		$this->assign('dingdan',$dingdan);
		$this->assign('total_fee',$total_fee);
		$this->assign('subject',$subject);
		$this->assign('body',$body);
		$this->assign('buyer_email',$buyer_email);
		$this->assign('trade_status',$trade_status);
		$this->display();

	}	

	

    public function theme() {
        $theme=D('Usertemplates');
        $tmdata = $theme->where("isopen=1")->order("ut_id")->select();
        $this->assign('theme',$tmdata);
        $this->assign('menu','theme');
        $this->display();
    }

    public function dotheme() {
        $bgcolor=trim($_POST['bg']);
        $textcolor=trim($_POST['text']);
        $links=trim($_POST['links']);
        $sidebarcl=trim($_POST['sidebarcl']);
        $sidebox=trim($_POST['sidebox']);
        $pictype=$_POST['pictype'];
        $newbgurl=$_POST['newbgurl'];

        if ($_FILES['bgpicture']['name']) {  //上传背景图
            import("@.ORG.UploadFile");
            $upload = new UploadFile();
            $upload->maxSize  = 2097152 ;
            $upload->allowExts  = explode(',','jpg,gif,png,jpeg');
            $upload->savePath =  './Public/attachments/photo/';
            $upload->thumb =  true;
            $upload->thumbPrefix   =  'theme_,thumb_';
            $upload->thumbMaxWidth =  '1280,112';
            $upload->thumbMaxHeight = '1280,72';
            $upload->subType = 'date';
            $upload->autoSub = true;
            $upload->suofang = '0,1';
            $upload->saveRule = time;
            $upload->thumbRemoveOrigin = true;
            if($upload->upload()) {
                $uploadList = $upload->getUploadFileInfo();

                $pictype=$pictype?$pictype:"center";
                $bgurl='photo/'.date('Ymd').'/thumb_'.$uploadList[0]['savename'];
            } else {
                echo "<script>alert('".$upload->getErrorMsg()."');location.href='".SITE_URL."/Setting/theme'</script>";
                exit;
            }
        }
        $newbgurl=$bgurl?$bgurl:$newbgurl;
        $newbgurl=daddslashes($newbgurl);

        $user=D('Users');
        $data['theme_bgcolor']=$bgcolor;
        $data['theme_pictype']=$pictype;
        $data['theme_text']=$textcolor;
        $data['theme_link']=$links;
        $data['theme_sidebar']=$sidebarcl;
        $data['theme_sidebox']=$sidebox;
        $data['theme_bgurl']=$newbgurl;
        $user->where("user_id='".$this->my['user_id']."'")->data($data)->save();

        Cookie::set('setok','theme1');
        header('location:'.SITE_URL.'/Setting/theme');
    }

    public function dltheme() {
        import("@.ORG.zip");
        $pre=C('DB_PREFIX');

        $theme_bgcolor = $this->my['theme_bgcolor']?$this->my['theme_bgcolor']:"#d3edfa";
        $theme_pictype = $this->my['theme_pictype']?$this->my['theme_pictype']:"left";
        $theme_text    = $this->my['theme_text']?$this->my['theme_text']:"#000000";
        $theme_link    = $this->my['theme_link']?$this->my['theme_link']:"#0066cc";
        $theme_sidebar = $this->my['theme_sidebar']?$this->my['theme_sidebar']:"#e2f2da";
        $theme_sidebox = $this->my['theme_sidebox']?$this->my['theme_sidebox']:"#b2d1a3";
        $isimg         = $this->my['theme_bgurl']?1:0;

        //文件内容和地址
        $filecont="INSERT INTO {$pre}usertemplates (theme_bgcolor,theme_pictype,theme_text,theme_link,theme_sidebar,theme_sidebox,theme_upload) VALUES ('$theme_bgcolor','$theme_pictype','$theme_text','$theme_link','$theme_sidebar','$theme_sidebox','$isimg')";
        $sqlfile=ET_ROOT."/Public/attachments/downtheme/theme.sql";
        $flname="Public/attachments/downtheme/theme_".$this->my['user_id'].".zip";

        //写入sql文件
        @unlink($sqlfile);
        $fp=fopen($sqlfile,"a");
        fwrite($fp,$filecont);
        fclose($fp);

        //文件列表
        if ($isimg) {
            $bgimgthumb=ET_ROOT."/Public/attachments/".$this->my['theme_bgurl'];
            $bgimg=thumb2theme($bgimgthumb);
            $files=array($bgimg,$bgimgthumb,$sqlfile);
        } else {
            $files=array($sqlfile);
        }

        //压缩
        if(is_array($files)){
            $zip = new zipfile();
            foreach($files as $file) {
                $this->listfiles($zip,$file);
            }
            $fp = fopen($flname, 'w');
            if(@fwrite($fp, $zip->file()) !== FALSE) {
                @unlink($sqlfile);
            }
            fclose($fp);
            header("location: ".str_replace('index.php','',SITE_URL)."/{$flname}");
        } else {
            Cookie::set('setok','theme2');
            header('location:'.SITE_URL.'/Setting/theme');
        }
    }

    private function listfiles($ZIP,$dir="."){
        if(is_file("$dir")){
            if(realpath($ZIP ->gzfilename)!=realpath("$dir")){
                $ZIP -> addfile(implode('',file("$dir")),basename($dir));
            }
        }
    }
}
?>